/*
 * $Id$
 *
 * Copyright 2008 HuangHuang. All rights reserved.
 */

package com.crm.web.page;

import org.apache.tapestry.html.BasePage;
import org.apache.tapestry.annotations.InjectState;
import org.apache.tapestry.annotations.InjectPage;
import org.apache.tapestry.IPage;
import org.apache.log4j.Logger;
import com.javaforge.tapestry.spring.annotations.InjectSpring;
import com.crm.service.IProcessService;
import com.crm.model.User;

import java.util.List;

/**
 * @author <a href="mailto:huang0510@hotmail.com">HuangHuang</a>
 * @version $Id$
 */
public abstract class ProcessHistory extends BasePage {

    private static Logger logger = Logger.getLogger(ProcessHistory.class);
    private int count;

    @InjectSpring("processService")
    public abstract IProcessService getProcessService();

    @InjectState("userSession")
    public abstract User getUserSession();

    @InjectPage("ProcessModify")
    public abstract ProcessModify getProcessModifyPage();

//    public void setPageParamUserCode(String page_param_userCode){
//        this.pageParamUserCode = page_param_userCode;
//    }
//
//    public String getPageParamUserCode(){
//        return pageParamUserCode;
//    }
//
//    public void setPageParamUserGroup(String page_param_userGroup){
//        this.pageParamUserGroup = page_param_userGroup;
//    }
//
//    public String getPageParamUserGroup(){
//        return pageParamUserGroup;
//    }

    public String getRecordCount() {
        return "共" + count + "条记录";
    }

    public List getEntries(){
        try{
            List list = getProcessService().getProcessByUser(getUserSession());
            count = list.size();
            return list;
        }
        catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return null;
        }
    }

//    public IPage newProcess(){
//        System.out.println("信息： New Process Info for " + getCustomerId());
//        ProcessNew page = getNewProcessPage();
//        page.setCustomerId(getCustomerId());
//        return page;
//    }

//    public IPage goback(){
//        return getCustomerSelectPage();
//    }

    public IPage onShowDetails(com.crm.model.Process process) {
        ProcessModify page = getProcessModifyPage();
        page.setProcess(process);
        page.setSourcePage(this.getPageName());
        return page;
    }
}